﻿Public Class FrmPrinter
    Private x_tscd_old As X_TSCD
    Private x_mayin_old As X_MayIn

    Private x_tscd As X_TSCD
    Private x_mayin As X_MayIn

    Private _parentForm As SuperForm

    Public Sub New(ByVal x_tscd1 As X_TSCD, ByVal x_mayin1 As X_MayIn, ByVal parentForm As SuperForm)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.x_tscd_old = x_tscd1
        Me.x_mayin_old = x_mayin1

        Me.x_tscd = x_tscd1
        Me.x_mayin = x_mayin1

        Me._parentForm = parentForm

        ini()

    End Sub

    Private Function ini() As Boolean
        Me.txtMaSo.Text = Me.x_tscd_old.getValue(I_TSCD.ColumnName_MaSO)
        Me.txtTen.Text = Me.x_tscd_old.getValue(I_TSCD.ColumnName_Ten)
        Me.txtDonVi.Text = Me.x_tscd_old.getValue(I_TSCD.ColumnName_DonViTrucThuoc)
        Me.txtNguyenGia.Text = Me.x_tscd_old.getValue(I_TSCD.ColumnName_NguyenGia)
        Me.txtTyLeHaoMon.Text = Me.x_tscd_old.getValue(I_TSCD.ColumnName_TyLeHaoMon)

        Me.txtHangSanXuat.Text = Me.x_mayin_old.getValue(I_MayIn.ColumnName_HangSanXuat)
        Me.dtpNamSanXuat.Text = Me.x_mayin_old.getValue(I_MayIn.ColumnName_NamSanXuat)
        Me.txtCongSuat.Text = Me.x_mayin_old.getValue(I_MayIn.ColumnName_CongSuat)
        Me.txtDoPhanGiai.Text = Me.x_mayin_old.getValue(I_MayIn.ColumnName_DoPhanGiai)
        Me.txtTocDoIn.Text = Me.x_mayin_old.getValue(I_MayIn.ColumnName_TocDoIn)
        Me.txtMucDichSd.Text = Me.x_mayin_old.getValue(I_MayIn.ColumnName_MucDichSuDung)

        Return True
    End Function

    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
        ini()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

        Me.x_tscd.setValue(I_TSCD.ColumnName_MaSO, CType(Me.txtMaSo.Text, String))
        Me.x_tscd.setValue(I_TSCD.ColumnName_Ten, CType(Me.txtTen.Text, String))
        Me.x_tscd.setValue(I_TSCD.ColumnName_DonViTrucThuoc, Me.txtDonVi.Text)
        Me.x_tscd.setValue(I_TSCD.ColumnName_NguyenGia, Me.txtNguyenGia.Text)
        Me.x_tscd.setValue(I_TSCD.ColumnName_TyLeHaoMon, Me.txtTyLeHaoMon.Text)
        Me.x_tscd.setValue(I_TSCD.ColumnName_FAType, CONSTANT.FIXED_ASSETS_TYPE._PRINTER)
        Me.x_tscd.setValue(I_TSCD.ColumnName_IsBusy, 0)
        Me.x_tscd.save(True)

        Me.x_mayin.setValue(I_MayIn.ColumnName_id, x_tscd.getValue(I_TSCD.ColumnName_id))
        Me.x_mayin.setValue(I_MayIn.ColumnName_HangSanXuat, Me.txtHangSanXuat.Text)
        Me.x_mayin.setValue(I_MayIn.ColumnName_NamSanXuat, Me.dtpNamSanXuat.Text)
        Me.x_mayin.setValue(I_MayIn.ColumnName_CongSuat, Me.txtCongSuat.Text)
        Me.x_mayin.setValue(I_MayIn.ColumnName_DoPhanGiai, Me.txtDoPhanGiai.Text)
        Me.x_mayin.setValue(I_MayIn.ColumnName_TocDoIn, Me.txtTocDoIn.Text)
        Me.x_mayin.setValue(I_MayIn.ColumnName_MucDichSuDung, Me.txtMucDichSd.Text)

        Me.x_mayin.save(True)


        Me._parentForm.loadFA()
        Me._parentForm.loadDetail()
        Me._parentForm.specifyCorrespondingDetail()

        Me.Close()

    End Sub
End Class